/**
 * \file
 * 		teleMainAppThread.cpp
 *
 * \brief
 *      Implements RPC Thread for some BLs' application.
 *
 * \par Author (last changes):
 *          - Song Li
 *          - BUIC, Continental Automotive Holdings Co., Ltd.
 * \par Project Leader:
 *          - Min Cai
 *          - BUIC, Continental Automotive Holdings Co., Ltd.
 * \par Responsible Developer:
 *          - Song Li
 *          - BUIC, Continental Automotive Holdings Co., Ltd.
 * \par Responsible Architect:
 *          - Zhang Fa
 *          - BUIC, Continental Automotive Holdings Co., Ltd.
 *
 * \par Project:
 *      DPCA2
 *
 * \par SW-Component:
 *      Telematics
 *
 * \par SW-Package:
 *      Telematics
 *
 * \par SW-Module:
 *      Telematics Application
 *
 * \par SW-Architecture Specification:
 *      DPCA2_SW_DD_Telematics(System)_V06B_Released
 *
 * \par SW-Design Specification:
 *      DPCA2_TELEMATICS_SW_DD_06b_release
 *
 * \par SW-Test Case Specification:
 *
 * \par CM-Info:
 *
 * \note
 *      This is a note.
 *
 * \bug
 *      - there are no known bugs
 *
 * \par Module-History:
 *
 * \verbatim
 * Date                Author					Reason
 * 10 Apr 2013         Song Li              Initial Creation
 * The latest entry at the head of the history list.
 * \endverbatim
 *
 * \par Copyright Notice:
 * Copyright (C) 2012 Continental Automotive Holdings Co., Ltd.
 * Alle Rechte vorbehalten. All Rights Reserved.\n
 * The reproduction, transmission or use of this document or its contents is
 * not permitted without express written authority.\n
 * Offenders will be liable for damages. All rights, including rights created
 * by patent grant or registration of a utility model or design, are reserved.
 *
 */

#include "StdAfx.h"

#ifndef _teleLogTrace_h
#include "teleLogTrace.h"
#endif

#include "teleMainAppThread.h"

/**
* \brief tlmPushObjAppThread: This function is a contructor of tlmPushObjAppThread
*
* \param
* - none
*
* \return
* - none
*
* \note
*/
teleMainAppThread::teleMainAppThread( char * name, ThreadPriorityType priority, ThreadStackSizeType stackSize ):
RPCThread (name,priority,stackSize),
pTlmPushObjApp(0),
pConnMgrApp(0),
pTlmUrlBackApp(0)
{

}

/**
* \brief ~tlmPushObjAppThread: This function is a destructor of tlmPushObjAppThread
*
* \param
* - none
*
* \return
* - none
*
* \note
*/
teleMainAppThread::~teleMainAppThread(void)
{
    if (NIL != pTlmPushObjApp){
        delete pTlmPushObjApp;
        pTlmPushObjApp = NIL;
    }

    if (NIL != pConnMgrApp){
        delete pConnMgrApp;
        pConnMgrApp = NIL;
    }

    if (NIL != pTlmUrlBackApp){
        delete pTlmUrlBackApp;
        pTlmUrlBackApp = NIL;
    }
}

/**
* \brief instantiate:
*	 - This is a over load function of the RPC Thread.
	 - Instantiate the tlmPushObjApp Application class.
*
* \param
* - none
*
* \return
* - none
*
* \note
*/
void teleMainAppThread::instantiate(void)
{
	LOG_PRINT(DPCA_TELE_MAIN_INFO,"[TELE]:%s\r\n",__FUNCTION__);

    //Create ConnMgrApp instance here, so that it runs in this thread
    pConnMgrApp = const_cast<ConnMgrApp*>(&(ConnMgrApp::getInstance()));

    //Create tlmPushObjApp instance here, so that it runs in this thread
	pTlmPushObjApp = const_cast<tlmPushObjApp*>(&(tlmPushObjApp::getInstance()));

	//Create tlmUrlBackApp instance here, so that it runs in this thread
	pTlmUrlBackApp = const_cast<tlmUrlBackApp*>(&(tlmUrlBackApp::getInstance()));
	//pTlmUrlBackApp = NIL;
}

/**
* \brief initialize:
*	 - This is a over load function of the RPC Thread.
*
* \param
* - none
*
* \return
* - none
*
* \note
*/
void teleMainAppThread::initialize(void)
{
	LOG_PRINT(DPCA_TELE_MAIN_INFO,"[TELE]:%s\r\n",__FUNCTION__);

    if ( NIL != pConnMgrApp ){
		pConnMgrApp->initialize();
	}

    if ( NIL != pTlmPushObjApp ){
		pTlmPushObjApp->initialize();
	}

	if ( NIL != pTlmUrlBackApp ){
		pTlmUrlBackApp->initialize();
	}
}

/**
* \brief initialize:
*	 - This is a over load function of the RPC Thread.
*	 - Release the handle of BT Media Application
* \param
* - none
*
* \return
* - none
*
* \note
*
*/
void teleMainAppThread::deInitialize(void) const /*DG CPP2ISQP-ISQPcpp Rule 8.7.1-SCC_GRANT_0006*/
{
	LOG_PRINT(DPCA_TELE_MAIN_INFO,"[TELE]:%s\r\n",__FUNCTION__);

    // DeInitialize the objects
    pTlmPushObjApp->deInitialize();
    pConnMgrApp->deInitialize();
    pTlmUrlBackApp->deInitialize();

    // Destroy the objects
    pTlmPushObjApp->destroyInstance();
    pConnMgrApp->destroyInstance();
    pTlmUrlBackApp->destroyInstance();
}

/**
* \brief onHook:
*	 - This is the callback function when the timer expired
*
* \param
* - none
*
* \return
* - none
*
* \note
*
*/
void teleMainAppThread::onHook(void)
{

}
